package com.maimao.spider.controller;

import com.maimao.spider.mapper.OptionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @author MaoLin Wang
 * @date 2020/11/26 5:01 下午
 */
@RequestMapping("/option")
@RestController
public class OptionController {

    @Autowired
    private OptionMapper optionMapper;

    @PostMapping("/do")
    @Transactional(rollbackFor = Exception.class)
    public String doInsert(@RequestBody Map<String,String> map){
        String detailId = map.get("detailId");
        String options = map.get("options");
        String colors="QHD+及以上,全高清FHD+,高清HD+,标清SD,QXGA+,其它分辨率";
//        String colors="白色,渐变色,金色,混合色,黑色,银色,红色,绿色,紫色,橙色,黄色,粉色,灰色,蓝色,极光色,石墨色,海蓝色,其他";
//        String option="4:03,16:9,18.5~19:9,19.1~19.5:9,19.6~20:9,20.1~20.5:9,20.6~21:9,21.9:9,22.5:18O,LED折叠屏,其它屏幕比例";
        String[] split = options.split(",");
        List<String> strings = Arrays.asList(split);
        optionMapper.insertBatch(Integer.parseInt(detailId),strings);
        return "ok";
    }
}
